package Utils
{
	import components.SharedDashboardManager;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.Button;
	import mx.controls.RichTextEditor;
	import mx.controls.Text;
	import mx.core.FlexGlobals;
	import mx.managers.PopUpManager;
	
	import objecthandles.ObjectHandles;
	
	public class RichTextUtil
	{
		private static var sdm:SharedDashboardManager = SharedDashboardManager.getInstance();
		private static var rte:RichTextEditor;
		private static var oh:ObjectHandles;
		
		public static function showRTEPopup(event:MouseEvent):void
		{
			rte = new RichTextEditor();
			rte.title = "Enter some text:";
			rte.width = 300;
			rte.height = 250;
			
			rte.addEventListener("initialize", addDoneButtonToRTE);
			
			PopUpManager.addPopUp(rte, FlexGlobals.topLevelApplication.dashboardCpnt.dashboard, false);
			PopUpManager.centerPopUp(rte);
		}
		
		private static function addDoneButtonToRTE(event:Event):void
		{
			var doneBtn:Button = new Button();
			doneBtn.label = "Done";
			doneBtn.addEventListener("click",rteDoneBtnClickHandler);
			rte.toolbar.addChild(doneBtn);
		}
		
		private static function rteDoneBtnClickHandler(event:MouseEvent):void
		{
			if(rte.text != "")
			{
				sdm.addText(rte.htmlText);
			}
			
			PopUpManager.removePopUp(rte);
		}
	}
}